package com.lx.fav.servlet;

import com.lx.fav.dao.TagMapper;
import com.lx.fav.entity.Tag;
import com.lx.fav.entity.User;
import com.lx.fav.util.MBHelp;
import com.lx.fav.util.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userTags")
public class MyTagsServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User userInfo = (User)req.getSession().getAttribute("userInfo");
        if(userInfo != null){
            List<Tag> tags = MBHelp.execute(session -> {
                TagMapper mapper = session.getMapper(TagMapper.class);
                return mapper.selectByUid(userInfo.getId());
            });
            Utils.outPut(resp, tags);
        }

    }
}
